home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mgr_2 / src / atari / bitmap.h < prev    next >
C/C++ Source or Header  |  1990-09-23  |  5KB  |  161 lines

  1. /*                        Copyright (c) 1987,1989 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: bitmap.h,v 4.2 88/07/19 14:19:23 sau Exp $
  9.     $Source: /tmp/mgrsrc/src/oblit/RCS/bitmap.h,v $
  10. */
  11. static char    h_bitmap_[] = "$Source: /tmp/mgrsrc/src/oblit/RCS/bitmap.h,v $$Revision: 4.2 $";
  12.  
  13. /* header file for SUN version of portable bitblit code (S. A. Uhler) */
  14.  
  15. #ifndef Min
  16. #define Min(x,y)    ((x)>(y)?y:x)
  17. #endif
  18.  
  19. /* Machine configurations go here */
  20.  
  21. /*
  22.  * DATA is the memory size of the frame buffer.  Usually "unsigned int",
  23.  * but sometimes "unsigned {long,short,char}" is more appropriate
  24.  */
  25.  
  26. typedef unsigned int DATA;                /* basic frame buffer word size */
  27. #define LOGBITS        5                /* Log2 of bits in type DATA */
  28.  
  29. /*
  30.  * The macro "GET Most Significant Bits" defines how the bits in each
  31.  * word map from memory to pixels on the display.  The top left most
  32.  * pixel on the display comes from either the *high* order or *low* order
  33.  * bit of the first frame buffer word.  Use "<<" in the first case, ">>"
  34.  * in the second.
  35.  * 
  36.  * The macro "GET Least Significant Bits" does the inverse of GETMSB
  37.  */
  38.  
  39. #define GETMSB(word,shift)    \
  40.     (word << shift)                    /* get most significant bits in word */
  41. #define GETLSB(word,shift) \
  42.     (word >> shift)                    /* get least significant bits in word */
  43.  
  44. /* these probably won't need changing */
  45.  
  46. #define BITS    (~(~0 << LOGBITS))            /* mask for bit# within word */
  47. #define MSB        (~GETLSB((unsigned)~0,1))    /* most sig bit set */
  48. #define LSB        (~GETMSB((unsigned)~0,1))    /* least sig bit set */
  49.  
  50. /*
  51.  * bitmap data has 2 formats, an internal format and an external format.
  52.  * (Sometimes the formats are the same).  The external format is native
  53.  * 68020 SUN/3, DATA aligned 1=black, 0=white.  The internal format is
  54.  * whatever the frame buffer is.  If DOFLIP is set, data is converted
  55.  * from external to internal format the first time it is used.  Bitmap
  56.  * data is recognized as being in external format if the _FLIP flag is
  57.  * set in the type field.  The installation routine flip() does the
  58.  * conversion.
  59.  */
  60.  
  61. #define DOFLIP (MSB==1)                            /* need to flip bytes */
  62.  
  63. /****************************/
  64.  
  65. #define ROP_INVERT(x) (x)                            /* punt for now */
  66.  
  67. /* bit_blit is defined as a macro so machines with special graphics 
  68.  * hardware can use mem_rop a a special case
  69.  */
  70.  
  71. #define bit_blit(dest,dx,dy,width,height,func,source,sx,sy)  \
  72.     mem_rop(dest,dx,dy,width,height,func,source,sx,sy) 
  73.  
  74. /* Macro to declare a static bitmap */
  75.  
  76. #define bit_static(name,wide,high,data,n)    \
  77.     BITMAP name = {(DATA *) data, &name, 0, 0, wide, high, _STATIC};
  78.  
  79. #define NULL_DATA    ((DATA *) 0)                /* NULL bitmap data */
  80. #define BIT_NULL    ((BITMAP *) 0)                /* NULL bitmap pointer */
  81.  
  82. #define IS_SCREEN(x)    (3&(x)->type==_SCREEN)    /* bitmap is on the display */
  83. #define IS_MEMORY(x)    (3&(x)->type==_MEMORY)    /* bitmap space malloc'd */
  84. #define IS_PRIMARY(x)    ((x)->primary == (x))
  85. #define SET_FLIP(x)     ((x)->primary->type |= DOFLIP ? _FLIP : 0)
  86.  
  87. /*
  88.  * OPCODE(expr), where expr is boolean expression involving SRC and DST,
  89.  * is one of sixteen numbers encoding a rasterop opcode. The values for SRC
  90.  * and DST are abitrary, as long as all 16 patterns may be produced by
  91.  * boolean combinations of them.
  92.  */
  93.  
  94. #define            DST     0xA    /* 1010 */
  95. #define            SRC    0xC    /* 1100 */
  96.  
  97. #define OPCODE(expr)    (0xF&(expr))
  98.  
  99. /* names for common bitblit functions */
  100.  
  101. #ifndef BIT_NOT
  102. #   define BIT_NOT(x)    (~(x))
  103. #endif
  104. #define BIT_SRC        SRC
  105. #define BIT_DST        DST
  106. #define BIT_SET        (BIT_SRC|BIT_NOT(BIT_SRC))
  107. #define BIT_CLR        (BIT_SRC&BIT_NOT(BIT_SRC))
  108. #define BIT_XOR        (BIT_SRC^BIT_DST)
  109. #define BIT_INVERT    (BIT_NOT(DST))
  110. #define GET_OP(x)    ((x)&0xf)        /* OPCODE, and GET_OP are redundant */
  111.  
  112. /* bitmap types */
  113.  
  114. #define _SCREEN        1        /* frame buffer */
  115. #define _MEMORY        2        /* malloc'd space */
  116. #define _STATIC        3        /* don't free space at destroy time */
  117. #define _FLIP            4        /* data is in external format */
  118.  
  119. /* member access macros */
  120.  
  121. #define BIT_X(x)    x->x0
  122. #define BIT_Y(x)    x->y0
  123. #define BIT_DATA(x)    x->data
  124. #define BIT_WIDE(x)    x->wide
  125. #define BIT_HIGH(x)    x->high
  126. #define BIT_DEPTH(x)    1        /* no color support for now */
  127.  
  128. #define BIT_SIZE(m) BIT_Size(BIT_WIDE(m), BIT_HIGH(m), BIT_DEPTH(m)) /* bytes */
  129. #define BIT_Size(wide,high,d)     (((d)*((wide+BITS)&~BITS)*high)>>3) /* bytes*/
  130. #define BIT_LINE(x)    ((x->primary->wide+BITS)>>LOGBITS)/* words on scan line */
  131.  
  132. /* structure and type definitions */
  133.  
  134. typedef struct bitmap {
  135.    DATA    *data;        /* bitmap data */
  136.    struct bitmap    *primary;    /* pointer to primary bitmap */
  137.    short        x0, y0;                /* starting coordinates, in bits */
  138.    short        wide, high;            /* bitmap size, in bits */
  139.    unsigned short    type;            /* bitmap type */
  140.    } BITMAP;
  141.  
  142. /* function declarations */
  143.  
  144. int mem_rop();
  145. int bit_destroy();
  146. int bit_line();
  147. BITMAP * bit_create();
  148. BITMAP * bit_alloc();
  149. BITMAP * bit_open();
  150.  
  151. /* for non existant color support */
  152.  
  153. #define DEPTH                1            /* bits per pixel */
  154. #define NOCOLOR         0xF
  155. #define GETCOLOR(x)     0
  156. #define PUTCOLOR(x)     0
  157.  
  158. /* other */
  159.  
  160. #define Bprintf(x)    /* gone */
  161.